	
	cap log close

*******************************************************************
/* title: eodb_replication_analysis.do */
/* description: replicating analysis from economic origins of dictatorship and democracy */
/* authors: dan slater, ben smith, gautam nair */
*******************************************************************

	clear
	set mem 500m
	set more off
	pause on 
	vers 10.0

*******************************************************************
* SET DIRECTORY & USE DATASET
*******************************************************************

	* set directory to folder containing replication data
	* cd ""
	* log using "eodb_replication_analysis_log.log", replace
	use "eodb_replication_data.dta"

*******************************************************************
*  TABLE 1 COUPS IN FULL SAMPLE
*******************************************************************

	* coup activity
	# delimit ;
	local coup_activity
	coup_success_gwf
	coup_success_n
	coup_attempt_n
	coup_plot_rumor_n
	;
	# delimit cr


	# delimit ;
	local controls_all 
	am_inc_gdp_ratio_l1
	wdi_ny_gdp_mktp_kd_zg_l1
	pwt_lngdppc_l1 
	pwt_kg_l1
	undp_manufacturing_share_l1 
	wdi_ny_gdp_totl_rt_zs_l1 
	wdi_log_population
	wdi_sp_pop_dpnd_ol_l1 
	pwt_openk_l1
	region_democ_cgv_gwf_l1
	coup_success_yrs_free_l1 
	time_trend_linear_l1 
	time_trend_quadratic_l1 
	time_trend_cubic_l1
	;
	# delimit cr

	# delimit ;
	local controls_unlagged 
	am_inc_gdp_ratio
	wdi_ny_gdp_mktp_kd_zg
	pwt_lngdppc 
	pwt_kg
	undp_manufacturing_share
	wdi_ny_gdp_totl_rt_zs 
	wdi_log_population
	wdi_sp_pop_dpnd_ol 
	pwt_openk
	region_democ_cgv_gwf
	coup_success_yrs_free 
	time_trend_linear
	time_trend_quadratic
	time_trend_cubic
	;
	# delimit cr

	# delimit ;
	local controls_unlagged_no_trends 
	am_inc_gdp_ratio
	wdi_ny_gdp_mktp_kd_zg
	pwt_lngdppc 
	pwt_kg
	undp_manufacturing_share
	wdi_ny_gdp_totl_rt_zs 
	wdi_log_population
	wdi_sp_pop_dpnd_ol 
	pwt_openk
	region_democ_cgv_gwf
	coup_success_yrs_free 
	;
	# delimit cr

	egen nonmissing= rownonmiss(`ivar1' `controls_all')
	egen nonmissingmax=max(nonmissing) if nonmissing!=.
	qui sum nonmissingmax
	local completedata="`r(max)'"

	* summary statistics
	tabstat `coup_activity' `controls_unlagged_no_trends', stats(mean sd min max n) format(%9.2f) col(stats) 

	* full sample: coup success regime transition
	nbreg coup_success_gwf `controls_all', cluster(ccode) iterate(20) irr

	* full sample: coup success regime transition OLS estimates
	reg coup_success_gwf  `controls_all', cluster(ccode)
	qui sum coup_success_gwf if e(sample)==1, d
	gen in_2=1 if e(sample)==1
	di _b[am_inc_gdp_ratio_l1]/`r(mean)'

	* full sample: coup success
	nbreg coup_success_n `controls_all', cluster(ccode) iterate(20) irr
	reg coup_success_n `controls_all', cluster(ccode)
	qui sum coup_success_n if e(sample)==1, d
	di _b[am_inc_gdp_ratio_l1]/`r(mean)'

	* full sample: coup attempt
	nbreg coup_attempt_n `controls_all', cluster(ccode) iterate(20) irr

	* full sample: coup plots + rumors
	nbreg coup_plot_rumor_n `controls_all', cluster(ccode) iterate(20) irr

*******************************************************************
* TABLE 2 DEMOCRACY SUBSAMPLE
*******************************************************************

	* democracy subsample: coup success regime transition
	nbreg coup_success_gwf `controls_all' if cgv_gwf_democracy_l1==1, cluster(ccode) iterate(20) irr

	* democracy subsample: coup success
	nbreg coup_success_n `controls_all' if cgv_gwf_democracy_l1==1, cluster(ccode) iterate(20) irr

	* democracy subsample: coup attempt
	nbreg coup_attempt_n `controls_all'  if cgv_gwf_democracy_l1==1, cluster(ccode) iterate(20) irr

	* democracy subsample: coup plots + rumors
	nbreg coup_plot_rumor_n `controls_all'  if cgv_gwf_democracy_l1==1, cluster(ccode) iterate(20) irr

*******************************************************************
* TABLE 3 POST-COUP REDISTRIBUTION
*******************************************************************

	* defining controls
	# delimit ;
	local controls_all 
	coup_success_gwf_l5
	wdi_ny_gdp_mktp_kd_zg 
	pwt_lngdppc
	undp_manufacturing_share 
	wdi_ny_gdp_totl_rt_zs 
	wdi_log_population 
	wdi_sp_pop_dpnd_ol
	pwt_openk
	region_democ_cgv_gwf
	time_trend_linear 
	time_trend_quadratic 
	time_trend_cubic
	;
	# delimit cr

	* level of direct taxes: full sample
	xtreg am_inc_gdp_ratio `controls_all', fe
	gen in_4_1=1 if e(sample)==1 
	* level of direct taxes: authoritarian regime
	xtreg am_inc_gdp_ratio `controls_all' if cgv_gwf_democracy==0, fe
	gen in_4_2=1 if e(sample)==1 
	* change in direct taxes: full sample
	xtreg am_inc_gdp_ratio_p5 `controls_all', fe
	* change in direct taxes: authoritarian regime
	xtreg am_inc_gdp_ratio_p5 `controls_all' if cgv_gwf_democracy==0, fe

*******************************************************************
* LOG CLOSE
*******************************************************************
	
	cap log close

